/*
 * Created on Jul 17, 2004
 */
package dk.aiszone.lang.autosource.generatorobjects.helpers;

import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import dk.aiszone.lang.autosource.generatorobjects.Import;
import dk.aiszone.lang.autosource.generatorobjects.interfaces.GeneratorObject;

/**
 * The <code>ImportList</code> contains a <code>Set</code> of <code>Imports</code>.
 * 
 * @author <a href="mailto:ais@mail.dk">Ais</a>
 * @since 1.0
 * @version 1.0
 */
public class ImportsList extends GeneratorObject implements Cloneable {

    private Set<Import> imports;

    /**
     * Default constructor for the <code>ImportList</code>.
     */
    public ImportsList() {
        this.imports = new TreeSet<Import>();
    }

    /**
     * Adds all the <code>Imports</code> of the supplied <code>ImportList</code><br>
     * to this <code>ImportList</code>.
     * 
     * @param _imports
     *            <code>ImportList</code> to add the <code>Imports</code> of.
     */
    public void addAll(ImportsList _imports) {
        this.imports.addAll(_imports.imports);
    }

    /**
     * Adds the supplied <code>Import</code> to the <code>ImportList</code>
     * 
     * @param _import
     *            The <code>Import</code> to add.
     */
    public void addImport(Import _import) {
        imports.add(_import);
    }

    /**
     * Add the supplied <code>Set</code> of <code>Imports</code> to the <code>ImportList</code>
     * 
     * @param _imports
     *            <code>Set</code> of <code>Imports</code> to add (<code>Set&lt;Import&gt;</code>).
     */
    public void addImports(Set<Import> _imports) {
        imports.addAll(_imports);
    }

    /**
     * Retrieve the <code>Imports</code> contained by the <code>ImportsList</code>.
     * 
     * @return Unmodifialble <code>Set</code> of <code>Imports</code>.
     */
    public Set<Import> getImports() {
        return Collections.unmodifiableSet(imports);
    }

    @Override
    public Object clone() {
        ImportsList clone = new ImportsList();

        for (Iterator<Import> iter = imports.iterator(); iter.hasNext();) {
            clone.addImport(iter.next());
        }

        return clone;
    }
}